<template>
  <div class="page-container">
    <pf-table
      ref="pfTable"
      v-model="form"
      :columns="columns"
      :form-items="formItems"
      @get-table-data="getTableData"
    >
      <template #handle="{row}">
        <el-button type="text" size="small" @click="showDetail(row)">详情</el-button>
      </template>
    </pf-table>
  </div>
</template>

<script>
import { PAY_METHOD_STATUS } from '@/utils/enum'

export default {
  name: 'CouponList',
  components: {
  },
  data() {
    return {
      payMethodOptions: PAY_METHOD_STATUS,
      form: {},
      loading: false
    }
  },
  computed: {
    columns() {
      const attrs = { 'min-width': '150px' }
      return [
        { label: '优惠券名称', prop: 'account', attrs },
        { label: '类型', prop: 'roleName', attrs },
        { label: '可用范围', prop: 'userName', attrs },
        { label: '优惠内容', prop: 'mobile', attrs },
        { label: '库存量', prop: 'mobile', attrs },
        { label: '发放量', prop: 'mobile', attrs },
        { label: '已使用比例', prop: 'sexStr', attrs },
        { label: '发放渠道', prop: 'sexStr', attrs },
        { label: '状态', slot: 'statusStr', attrs },
        { label: '操作', slot: 'handle', attrs: { width: '200px' }}
      ]
    },
    formItems() {
      const labelWidth = '110px'
      return [
        {
          type: 'input',
          label: '优惠券名称',
          prop: 'roleName',
          formItemAttrs: { labelWidth }
        }, {
          type: 'select',
          label: '类型',
          prop: 'roleName'
        }, {
          type: 'select',
          label: '状态',
          prop: 'roleName'
        }
      ]
    }
  },

  methods: {

    getTableData({ pageNo, pageSize, ...formQuery }, done) {
      this.loading = true
      // const [createStartTime = '', createEndTime = ''] = formQuery?.dateRange || []
      // const data = {
      //   pageNo,
      //   pageSize,
      //   createStartTime,
      //   createEndTime,
      //   ...formQuery
      // }
      // getRoleList(data).then(res => {
      //   this.loading = false
      //   done({ data: res.data || [], total: res.count || 0 })
      // }).catch(() => {
      //   done({ data: [], total: 0 })
      //   this.loading = false
      // })
      done({ data: [1], total: 0 })
    },

    // 详情
    showDetail(row) {
      this.$router.push({
        path: '/marketing/coupon/detail',
        query: {
          id: row.id
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped></style>
